var UserLayers = function () {
	
	var options;
	
	var grid = new Datatable();

    var handle = function () {
    	
        grid.init({
            src: $("#datatable_userlayers"),
            fixedColumns: 1,
            onSuccess: function (data) {
            	
            },
            onError: function (data) {
               
            },
            dataTable: {
                "pageLength": 10,
                "ajax": {
                    "url": options.ctx + '/userlayer/list'
                },
                "columnDefs": [{'orderable': false, 'targets': [0]}],
                "columns": [
                            {"data": "id", "render": function(data,type,full) {
								return '<div class="btn-group">'+
										'	<a href="#" class="btn blue-madison btn-xs btn-operation" data-toggle="dropdown">'+
										'		<i class="fa fa-cog"></i> ' + message['datatable.operation'] + 
										'	</a>'+
										'	<ul class="dropdown-menu pull-left">'+
										'		<li><a href="' + options.ctx + '/userlayer/update/' + full.id + '" data-toggle="modal" data-target="#ajax-modal">修改</a></li>'+
										'		<li><a href="#this" onClick="UserLayers.Delete(' + full.id + ', \'' + full.name + '\')">删除</a></li>'+
										'		<li><a href="#">分层</a></li>'+
										'		<li><a href="#">第三方支付设置</a></li>'+
										'		<li><a href="#">收款银行设置</a></li>'+
										'		<li><a href="#this" onClick="UserLayers.SetDefault(' + full.id + ', \'' + full.name + '\')">设为默认分层</a></li>'+
										'	</ul>'+
										'</div>';
							}},
                            {"data": "deep"},
                            {"data": "name", "render": function(data,type,full){
								return full.isDefault ? data + ' <span class="label label-sm label-success">默认</span>' : data;
							}},
                            {"data": "description"},
                            {"data": "layerUsers"},
                            {"render": function(data,type,full){
								return full.registerBeginTime + ' - ' + full.registerEndTime;
							}},
							
							{"data": "withdrawTimes"},
							{"data": "withdrawTotal", "class": "right"},
                            {"data": "rechargeTimes"},
							{"data": "rechargeTotal", "class": "right"},
							{"data": "rechargeMax", "class": "right"},
							
							{"data": "oneTimeWithdrawAmountMin", "class": "right"},
							{"data": "oneTimeWithdrawAmountMax", "class": "right"},
							{"data": "dailyWithdrawTimesMax"},
							{"data": "dailyWithdrawAmountMax", "class": "right"},
							{"data": "oneTimeRechargeAmountMin", "class": "right"},
							{"data": "oneTimeRechargeAmountMax", "class": "right"},
							{"data": "dailyRechargeTimesMax"},
							{"data": "dailyRechargeAmountMax", "class": "right"},
							
							{"data": "createdBy"},
                        	{"data": "createdDate"},
                        	{"data": "lastModifiedBy"},
                        	{"data": "lastModifiedDate"}
                        ],
                "order": [
                    [1, "asc"]
                ]
            }
        });
        
    };

    return {
        init: function (opts) {
			options = $.extend(true, {}, opts);
            handle();
        },
		
		Delete: function(id, name) {
			bootbox.confirm("确定删除" + name + "吗？<br/><br/>删除后该分层的用户将移至默认分层！", function(result) {
			   if (result) {
				   Metronic.sendRequest({
					   url: options.ctx + '/userlayer/delete/' + id,
					   dataTable: grid.getDataTable()
				   });
			   }
			}); 
		},
		
		SetDefault: function(id, name) {
			bootbox.confirm("确定将" + name + "设为默认分层吗？", function(result) {
			   if (result) {
				   Metronic.sendRequest({
					   url: options.ctx + '/userlayer/setdefault/' + id,
					   dataTable: grid.getDataTable()
				   });
			   }
			}); 
		}
    };

}();

